package org.laobai.shop.admin.controller;

import javax.servlet.http.HttpServletRequest;

import org.laobai.shop.goods.entity.Admin;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("admin")
@Controller
public class AdminController {
	
	@RequestMapping("toLogin")
	public String toLogin(){
		return "login";
	}
	
	@RequestMapping("login")
	public String login(Admin admin,HttpServletRequest request){
		// 正常逻辑
		/*
		 1、根据用户名查询数据库
		 2、数据不存在 提示用户名或密码错误
		 3、数据存在，比对密码  如果一致则成功
		 */
		if(admin!=null){
			if("zs".equals(admin.getUsername())&& "123".equals(admin.getPwd())){
				request.getSession().setAttribute("ADMIN", admin);
				
				return "redirect:/index";
			}
		}
		
		
		return "login";
	}
}
